﻿using System.Web.Mvc;
using System.Web.Routing;

namespace iHouse.Web.Infrastructure
{
    public class Routes
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
            routes.IgnoreRoute("Upload/{*imageUrl}");
            routes.IgnoreRoute("{*favicon}", new { favicon = @"(.*/)?favicon.ico(/.*)?" });
            routes.IgnoreRoute("Scripts/{*scriptUrl}");

#if ! DEBUG
            routes.MapRoute(
                "",
                "default",
                new { controller = "Book", action = "List" }
                );
#endif

            routes.MapRoute(
                "GetByCategory",
                "{controller}/Category/{category}",
                new { controller = "Book", action = "ListByCategory", category = 0 },
                new { category = "[0-9]+" }
                );//URL:/Book/Category/1


            routes.MapRoute(
                 "BookEdit",
                 "Book/Edit/{bookID}",
                 new { controller = "Book", action = "Edit", bookID = (int?)null },
                 new { bookID = "[0-9]+" }
             );  //URL:/Book/EditBook/1

            routes.MapRoute(
                 "BookDelete",
                 "Book/Delete/{bookID}",
                 new { controller = "Book", action = "Delete", bookID = (int?)null },
                 new { bookID = "[0-9]+" }
             );  //URL:/Book/DeleteBook/1

            routes.MapRoute(
                 "NoteUpdate",
                 "Note/Edit/{noteID}",
                 new { controller = "Note", action = "Edit", noteID = (int?)null },
                 new { noteID = "[0-9]+" }
             );  //URL:/Note/UpdateNote/1

            routes.MapRoute(
                 "NoteDelete",
                 "Note/Delete/{noteID}",
                 new { controller = "Note", action = "Delete", noteID = (int?)null },
                 new { noteID = "[0-9]+" }
             );  //URL:/Note/DeleteNote/1

            routes.MapRoute(
                "CategoryAction",
                "Category/{action}/{id}",
                new { controller = "Category" },
                new { id = "[0-9]+" }
            );  //URL:/Category/Update/1;/Category/Delete/2

            routes.MapRoute(
                "PublisherAction",
                "Publisher/{action}/{id}",
                new { controller = "Publisher" },
                new { id = "[0-9]+" }
            );  //URL:/Publisher/Update/1;/Publisher/Delete/2

            routes.MapRoute(
              "Default",
              "{controller}/{action}",
              new { controller = "Book", action = "HomeList" },
              new[] { "iHouse.Web.Controllers"}
            );  //URL:/Book/CreateBook;/Category/GetGridData;/Category/Create;/Category/List
        }

    }
}
